//
//  AnimationView.m
//  购买动画2
//
//  Created by rimi on 16/8/2.
//  Copyright © 2016年 周伦. All rights reserved.
//

#import "AnimationView.h"

@interface AnimationView ()

@property (nonatomic,strong)UIBezierPath *circlePath1;
@property (nonatomic,strong)UIView       *subView;
@property (nonatomic,strong)UIImageView  *imageview;

@end

@implementation AnimationView

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        self.shapeLayer = [CAShapeLayer layer];
        _shapeLayer.frame = frame;
            _shapeLayer.fillColor = [UIColor clearColor].CGColor;
            _shapeLayer.lineWidth = 1.0f;
            _shapeLayer.strokeColor = [UIColor clearColor].CGColor;
        _circlePath1 = [UIBezierPath bezierPath];
        //起始坐标
        [_circlePath1 moveToPoint:CGPointMake(510, 470)];
        //终点坐标，第一个点的坐标，和第二个点的坐标
        [_circlePath1 addCurveToPoint:CGPointMake(40, 710) controlPoint1:CGPointMake(50, 200) controlPoint2:CGPointMake(180, 500)];
        _shapeLayer.path = _circlePath1.CGPath;
        //stroke：用笔画点意思
        _shapeLayer.strokeStart = 0;
        
        _shapeLayer.strokeEnd = 1.0;


        [self.layer addSublayer:_shapeLayer];
//        [self imageview];
    }
    return self;
}

+ (instancetype)instanceAnimationView {
    static AnimationView *view = nil;
    if (view == nil) {
        view = [[AnimationView alloc]initWithFrame:[UIScreen mainScreen].bounds];
    }
    return view;
}

- (void)addAnimation {
    //抛物效果动画
    CAKeyframeAnimation *animation = [CAKeyframeAnimation animationWithKeyPath:@"position"];
    //动画持续时间
//    animation.duration = 2;
    
    animation.timingFunction = [CAMediaTimingFunction functionWithName:@"easeInEaseOut"];
    //重复的次数
    animation.repeatCount = 1;
    animation.path = _circlePath1.CGPath;
    //缩小效果
    CABasicAnimation *narrow = [CABasicAnimation animationWithKeyPath:@"transform.scale"];
    narrow.duration = 1.0f;
    //出来时候的图片大小
    narrow.fromValue = [NSNumber numberWithFloat:2.0f];
    //byValue 是从小放大
//    narrow.byValue = [NSNumber numberWithFloat:1.0f];
    //消失时候图片的大小
    narrow.toValue = [NSNumber numberWithFloat:0.1f];
    narrow.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseIn];
    
    //组合这两个动画
    CAAnimationGroup *group = [CAAnimationGroup animation];
    group.animations = @[animation,narrow];
    //动画的总时间
    group.duration = 1.0f;
    

    
    _subView = [[UIView alloc] initWithFrame:CGRectMake(-160, 720, 57, 57)];
    
//    _subView.backgroundColor = [UIColor redColor];
    _subView.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"Icon.png"]];

    

    [self addSubview:_subView];
    
    [_subView.layer addAnimation:group forKey:@"test"];
//    [subView.layer addAnimation:scaleAnimation forKey:@"test"];
}





@end
